package training_camp.day4.leetcode24;

class Solution {
    public ListNode swapPairs(ListNode head) {
        ListNode first;
        ListNode curr;
        ListNode temp;
        ListNode second;
        ListNode dummyHead = new ListNode();
        dummyHead.next = head;
        curr = dummyHead;
        while(curr.next!=null &&curr.next.next!=null){
            temp = curr.next.next.next;
            first = curr.next;
            second = curr.next.next;
            first.next = temp;
            second.next = first;
            curr.next = second;
            curr = first;
        }
        return dummyHead.next;
    }
}